package com.zmj.sy.mom.srv.aps;

import lombok.extern.slf4j.Slf4j;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.core.env.Environment;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.util.StringUtils;
import org.springframework.web.client.RestTemplate;

import java.net.InetAddress;
import java.net.UnknownHostException;

@EnableFeignClients({"com.zmj.sy.mom.srv.mbd.api.api", "com.zmj.sy.mom.srv.aps.feign"})
@EnableScheduling
@SpringBootApplication
@Slf4j
public class MomSrvApsApplication {

    public static void main(String[] args) throws UnknownHostException {
        ConfigurableApplicationContext application =	SpringApplication.run(MomSrvApsApplication.class, args);
        Environment env = application.getEnvironment();
        String ip = InetAddress.getLocalHost().getHostAddress();
        String port = env.getProperty("server.port");
        String path =env.getProperty("server.servlet.context-path");
        if(StringUtils.isEmpty(path)) {
            path="";
        }
        log.info("\n----------------------------------------------------------\n\t" +
                "Application APS is running! Access URLs:\n\t" +
                "Local: \t\thttp://localhost:" + port + path + "/\n\t" +
                "External: \thttp://" + ip + ":" + port + path + "/\n\t" +
                "Swagger文档: \thttp://" + ip + ":" + port + path + "/doc.html\n" +
                "----------------------------------------------------------");
    }

    @Bean
    @LoadBalanced
    RestTemplate restTemplate() {
        return new RestTemplate();
    }

}
